#include "skynet_flow.h"

template<
	unsigned BIT_IN,
	unsigned N_BATCH
>
void load_ifm_ptr(ap_uint<BIT_IN>* ifm, std::string path, unsigned VEC_LEN)
{
	FILE *fp = fopen(path.c_str(), "rb");
	fread(ifm, 1, VEC_LEN*sizeof(ap_uint<BIT_ACTV>), fp); 
	for(unsigned b=1; b < N_BATCH; b++)
	{
		for(unsigned i=0; i < VEC_LEN*BIT_ACTV/BIT_IN; i++)
		{
			ifm[b*VEC_LEN*BIT_ACTV/BIT_IN+i] = ifm[i];
		}
	}
	fclose(fp);
}

template<
	unsigned N_BATCH
>
int32_t check_cfm_ptr(ODT* ofm, std::string path, unsigned VEC_LEN)
{
    ODT* ofm_buffer;
	ofm_buffer =  (ODT*)malloc(VEC_LEN*sizeof(ODT));
	FILE *fp = fopen(path.c_str(), "rb");
	fread(ofm_buffer, 1, VEC_LEN*sizeof(ODT), fp);
	fclose(fp);

	int32_t error_cnt = 0;
	for(size_t b=0; b < N_BATCH; b++)
	{
		for(size_t i=0; i < VEC_LEN; i++)
		{
			if(abs(ofm[b*VEC_LEN+i]-ofm_buffer[i])>4)
			{
				std::cout << i << " " << (int32_t)ofm[b*VEC_LEN+i] << " " << (int32_t)ofm_buffer[i] << std::endl;
				error_cnt++;
			}
		}
	}
	free(ofm_buffer);
	return error_cnt;
}